//
// Created by Administrator on 2021/10/16.
//
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <climits>

using namespace std;

class Solution {
public:
    int maximumUnits(vector<vector<int>> &boxTypes, int truckSize) {
        sort(boxTypes.begin(), boxTypes.end(), [](vector<int> &a, vector<int> &b) {
            return a[1] > b[1];
        });
        int ans = 0;
        for (int i = 0; i < boxTypes.size() and truckSize > 0; ++i) {
            int num = min(boxTypes[i][0], truckSize);
            truckSize -= num;
            ans += num * boxTypes[i][1];
        }
        return ans;
    }
};

int main() {
    vector<vector<int>> boxTypes{{1, 3},
                                 {2, 2},
                                 {3, 1}};
    Solution solution;
    cout << solution.maximumUnits(boxTypes, 4) << endl;
    return 0;
}
